package com.tong;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

public class Initialization implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    private RedisService redisService;

    //初始化方法, 保证只执行一次
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        if (contextRefreshedEvent.getApplicationContext().getParent() == null) {
//            redisService.incr("num",1);
//            System.out.println(redisService.get("num"));
        }
    }
}
